package org.atlantis.uzw.base.http;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang3.builder.ToStringBuilder;

public class HttpRequest {

	public static enum HttpMethod {
		GET, POST;
	}

	private HttpMethod method;
	private String url;
	private Map<String, String> params = new HashMap<>();

	public static HttpRequest get(String url) {
		return new HttpRequest(url, HttpMethod.GET);
	}

	public static HttpRequest post(String url) {
		return new HttpRequest(url, HttpMethod.POST);
	}

	private HttpRequest(String url, HttpMethod method) {
		this.url = url;
		this.method = method;
	}

	public HttpRequest param(String name, String value) {
		params.put(name, value);
		return this;
	}

	public HttpRequest params(Map<String, String> paramMap) {
		params.putAll(paramMap);
		return this;
	}

	public String getUrl() {
		return url;
	}

	public Map<String, String> getParams() {
		return params;
	}

	public HttpMethod getMethod() {
		return method;
	}

	@Override
	public String toString() {
		ToStringBuilder builder = new ToStringBuilder(this);
		builder.append("method", method);
		builder.append("url", url);
		for (Entry<String, String> param : params.entrySet()) {
			builder.append("param." + param.getKey(), param.getValue());
		}
		return builder.toString();
	}
}
